//
//  chongZhiTiXianRecordVC.m
//  jiaKaoZhuShou
//
//  Created by 金艺社 on 2018/5/23.
//  Copyright © 2018年 金艺社. All rights reserved.
//

#import "chongZhiTiXianRecordVC.h"
#import "headView.h"
#import "chongZhiYiXianCell.h"
#import "chongZhiTiXianModel.h"
@interface chongZhiTiXianRecordVC ()
@property (nonatomic, strong) NSMutableArray *dataList;
@end

@implementation chongZhiTiXianRecordVC

- (void)viewDidLoad {
    headView *view = [[headView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
    if ([self.title isEqualToString:@"充值记录"]) {
        view.leftLab.text = @"支付方式/时间";
    }else {
        view.leftLab.text = @"提现至/时间";
    }
    view.rightLab.text = @"金额(元)/状态";
    [self.view addSubview:view];
    CGRect frame = CGRectMake(0, 30, kScreenWidth, kScreenHeight - StatusBarAndNavigationBarHeight - TabbarSafeBottomMargin - 30);
    self.tableView = [[UITableView alloc]initWithFrame:frame];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        //        if (iPhoneX) {
        //            self.detialView.contentInset = UIEdgeInsetsMake(0, 0, 88, 0);
        //        }else {
        //            self.detialView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);
        //        }
        //        self.detialView.scrollIndicatorInsets = self.detialView.contentInset;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self confingureTableView];
    [self listRequest];
}

// MARK: - 下拉刷新
- (void)addRefreshHeader {
    [super addRefreshHeader];
}

- (void)confingureTableView {
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.separatorColor = [UIColor clearColor];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([chongZhiYiXianCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([chongZhiYiXianCell class])];
}

#pragma mark --- uitableViewDelegate and dataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataList.count;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 65;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    chongZhiYiXianCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([chongZhiYiXianCell class])];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = [self.dataList objectAtIndex:indexPath.section];
    if (![self.title isEqualToString:@"充值记录"]) {
        cell.order_lab.hidden = YES;
        cell.name_lab.text = cell.model.bankName;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 20)];
    grayView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    return grayView;
}
//充值提现记录数据请求
- (void)listRequest {
    NSDictionary *dic = @{
                          @"token":USERTOKEN,
                          };
    NSString *url;
    __weak typeof(self) weakSelf = self;
    if ([self.title isEqualToString:@"充值记录"]) {
        url  = [NSString stringWithFormat:@"%@", [[apiManger shareApiManger] RechargeList]];
    }else {
        url  = [NSString stringWithFormat:@"%@", [[apiManger shareApiManger] withdrawalRecord]];
    }
   
    [networkManger PostHttpDataWithUrlStr:url Dic:dic SuccessBlock:^(id responseObject) {
        if ([responseObject[@"rcd"] isEqualToString:R0001]) {
            if ([self.title isEqualToString:@"充值记录"]) {
                self.dataList = [chongZhiTiXianModel mj_objectArrayWithKeyValuesArray:responseObject[@"userRechargesList"]];
            }else {
                self.dataList = [chongZhiTiXianModel mj_objectArrayWithKeyValuesArray:responseObject[@"userCashList"]];
            }
            [weakSelf.tableView reloadData];
            if (self.dataList.count == 0) {
                [MBProgressHUD gk_toastShowMessage:@"没有相关记录"];
            }
        }else{
            [MBProgressHUD gk_toastShowMessage:responseObject[@"rmg"]];
        }
    } FailureBlock:^(id error) {
        [MBProgressHUD gk_toastShowMessage:@"请求失败"];
    }];
}
//
- (NSMutableArray *)dataList {
    if (!_dataList) {
        _dataList = [NSMutableArray array];
    }
    return _dataList;
}
@end
